package linux.crontab;

import java.text.SimpleDateFormat;
import java.util.ArrayList;

/**
 * 定时任务测试类
 *
 * @author 832659942@qq.com 2017/05/12 10:05
 */
public final class Test {
	static final SimpleDateFormat SDF = new SimpleDateFormat("MM-dd HH:mm:ss SSS");

	// 每1秒
	// 测试ok
	public static void main_1_(String[] args) {
		CronMgr.startService();
		final ArrayList<CronDb> lst = new ArrayList<CronDb>();
		CronDb cronDb;
		int id;
		Object runner;
		long t0, t1;
		int n9;
		String MM, wk, dd, HH, mt, ss;

		id = 1;
		t0 = 0;
		t1 = 0;
		n9 = 0;
		MM = null;
		wk = null;
		dd = null;
		HH = null;
		mt = null;
		ss = null;
		runner = "ss=null";
		cronDb = new CronDb(id, runner, t0, t1, n9, MM, wk, dd, HH, mt, ss);
		lst.add(cronDb);

		final CronDb[] arr = new CronDb[lst.size()];
		lst.toArray(arr);
		CronMgr.resetCronQueue(arr);
	}

	// 每1秒
	// 测试ok
	public static void main_2_(String[] args) {
		CronMgr.startService();
		final ArrayList<CronDb> lst = new ArrayList<CronDb>();
		CronDb cronDb;
		int id;
		Object runner;
		long t0, t1;
		int n9;
		String MM, wk, dd, HH, mt, ss;

		id = 1;
		t0 = 0;
		t1 = 0;
		n9 = 0;
		MM = null;
		wk = null;
		dd = null;
		HH = null;
		mt = null;
		ss = "/1";
		runner = "每1秒";
		cronDb = new CronDb(id, runner, t0, t1, n9, MM, wk, dd, HH, mt, ss);
		lst.add(cronDb);

		final CronDb[] arr = new CronDb[lst.size()];
		lst.toArray(arr);
		CronMgr.resetCronQueue(arr);
	}

	// 每3秒，并限制开始终止时间
	// 测试ok
	public static void main_3_(String[] args) throws Exception {
		final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		CronMgr.startService();
		final ArrayList<CronDb> lst = new ArrayList<CronDb>();
		CronDb cronDb;
		int id;
		Object runner;
		long t0, t1;
		int n9;
		String MM, wk, dd, HH, mt, ss;

		id = 1;
		t0 = sdf.parse("2017-05-22 11:38:40").getTime() / 1000 * 1000;
		t1 = sdf.parse("2017-05-22 11:45:30").getTime() / 1000 * 1000;
		n9 = 0;
		MM = null;
		wk = null;
		dd = null;
		HH = null;
		mt = null;
		ss = "/3";
		runner = "每3秒 11:38:40~11:45:30";
		cronDb = new CronDb(id, runner, t0, t1, n9, MM, wk, dd, HH, mt, ss);
		lst.add(cronDb);

		final CronDb[] arr = new CronDb[lst.size()];
		lst.toArray(arr);
		CronMgr.resetCronQueue(arr);
	}

	// 1 3 5 21
	// 测试ok
	public static void main_4_(String[] args) {
		CronMgr.startService();
		final ArrayList<CronDb> lst = new ArrayList<CronDb>();
		CronDb cronDb;
		int id;
		Object runner;
		long t0, t1;
		int n9;
		String MM, wk, dd, HH, mt, ss;

		id = 1;
		t0 = 0;
		t1 = 0;
		n9 = 0;
		MM = null;
		wk = null;
		dd = null;
		HH = null;
		mt = null;
		ss = "1 3 5 21";
		runner = "1 3 5 21";
		cronDb = new CronDb(id, runner, t0, t1, n9, MM, wk, dd, HH, mt, ss);
		lst.add(cronDb);

		final CronDb[] arr = new CronDb[lst.size()];
		lst.toArray(arr);
		CronMgr.resetCronQueue(arr);
	}

	// 1 3 21 5
	// 测试fail
	// 你HYB可以看它的执行效果：会发现"下一分钟的第5秒钟"没有执行
	// 下一个版本v02，要解决这个问题
	// 最后做的时候，想想，不做这个事情了，用任务开始时间来控制即可。
	// 你HYB想想，到了下一分钟，在第5秒钟执行，那第1秒第3秒咋办？
	public static void main_5_(String[] args) {
		CronMgr.startService();
		final ArrayList<CronDb> lst = new ArrayList<CronDb>();
		CronDb cronDb;
		int id;
		Object runner;
		long t0, t1;
		int n9;
		String MM, wk, dd, HH, mt, ss;

		id = 1;
		t0 = 0;
		t1 = 0;
		n9 = 0;
		MM = null;
		wk = null;
		dd = null;
		HH = null;
		mt = null;
		ss = "1 3 21 5";
		runner = "1 3 21 5";
		cronDb = new CronDb(id, runner, t0, t1, n9, MM, wk, dd, HH, mt, ss);
		lst.add(cronDb);

		final CronDb[] arr = new CronDb[lst.size()];
		lst.toArray(arr);
		CronMgr.resetCronQueue(arr);
	}

	public static void main_6_(String[] args) {
		CronMgr.startService();
		final ArrayList<CronDb> lst = new ArrayList<CronDb>();
		CronDb cronDb;
		int id;
		Object runner;
		long t0, t1;
		int n9;
		String MM, wk, dd, HH, mt, ss;

		id = 1;
		t0 = 0;
		t1 = 0;
		n9 = 0;
		MM = null;
		wk = null;
		dd = null;
		HH = null;
		mt = "/2";
		ss = null;
		runner = "mt=" + mt + " ss=" + ss;
		cronDb = new CronDb(id, runner, t0, t1, n9, MM, wk, dd, HH, mt, ss);
		lst.add(cronDb);

		final CronDb[] arr = new CronDb[lst.size()];
		lst.toArray(arr);
		CronMgr.resetCronQueue(arr);
	}

	public static void main_7_(String[] args) {
		CronMgr.startService();
		final ArrayList<CronDb> lst = new ArrayList<CronDb>();
		CronDb cronDb;
		int id;
		Object runner;
		long t0, t1;
		int n9;
		String MM, wk, dd, HH, mt, ss;

		id = 1;
		t0 = 0;
		t1 = 0;
		n9 = 0;
		MM = null;
		wk = null;
		dd = null;
		HH = null;
		mt = "/2";
		ss = "/5";
		runner = "mt=" + mt + " ss=" + ss;
		cronDb = new CronDb(id, runner, t0, t1, n9, MM, wk, dd, HH, mt, ss);
		lst.add(cronDb);

		final CronDb[] arr = new CronDb[lst.size()];
		lst.toArray(arr);
		CronMgr.resetCronQueue(arr);
	}

	public static void main_8_(String[] args) {
		CronMgr.startService();
		final ArrayList<CronDb> lst = new ArrayList<CronDb>();
		CronDb cronDb;
		int id;
		Object runner;
		long t0, t1;
		int n9;
		String MM, wk, dd, HH, mt, ss;

		id = 1;
		t0 = 0;
		t1 = 0;
		n9 = 0;
		MM = null;
		wk = null;
		dd = null;
		HH = null;
		mt = "18 20 22 24 30";
		ss = "1 3 5";
		runner = "mt=" + mt + " ss=" + ss;
		cronDb = new CronDb(id, runner, t0, t1, n9, MM, wk, dd, HH, mt, ss);
		lst.add(cronDb);

		final CronDb[] arr = new CronDb[lst.size()];
		lst.toArray(arr);
		CronMgr.resetCronQueue(arr);
	}

	public static void main/*_9_*/(String[] args) throws Exception {
		CronMgr.startService();
		final ArrayList<CronDb> lst = new ArrayList<CronDb>();
		CronDb cronDb;
		int id;
		Object runner;
		long t0, t1;
		int n9;
		String MM, wk, dd, HH, mt, ss;

		id = 1;
		t0 = 0;
		t1 = 0;
		n9 = 0;
		MM = null;
		wk = null;
		dd = null;
		HH = "0 2 3";
		mt = "10 12 15";
		ss = "10 12 15";
		runner = "HH=" + HH + " mt=" + mt + " ss=" + ss;
		cronDb = new CronDb(id, runner, t0, t1, n9, MM, wk, dd, HH, mt, ss);
		lst.add(cronDb);

		final CronDb[] arr = new CronDb[lst.size()];
		lst.toArray(arr);
		CronMgr.resetCronQueue(arr);

		while (System.in.read() != '*')
			CronMgr.notifyCronQueue();
	}

}
